<?php
namespace app\admin\controller;


use think\Request;

class Product extends Base{


    public function shop(){

        $shop = getUserShop('system');
        $this->assign('shop',$shop);
        return view('shop');
    }

    public function saveShop(){
        $name = Request::instance()->post('name');
        $phone = Request::instance()->post('phone');
        $img = Request::instance()->file('img');
        model('shop')->saveShop('system',$name,$phone,$img);
        $this->redirect('product');
    }


    public function product(){
        $data = model('product')->getShopProduct('system');
        if($data){
            $this->assign('data',$data);
            return view('product');
        }
        else{
            $this->redirect('shop');
        }
    }


    public function addProduct(){
        $shop = getUserShop('system');
        $this->assign('shop',$shop);
        return view('addProduct');
    }

    public function updateProduct($id){
        $product = model('product')->where('id',$id)->find();
        $guige = model('product_guige')->where('productId',$id)->select();
        $shop = getUserShop('system');
        $this->assign('product',$product);
        $this->assign('guige',$guige);
        $this->assign('shop',$shop);
        return view('updateProduct');
    }

    public function saveProduct(){
        $data = Request::instance()->post();
        $img = Request::instance()->file('img');
        $data['uid']=0;
        model('product')->saveProduct($data,$img);
        $this->redirect('product');
    }

    public function saveRecharge(){
        $data = Request::instance()->post();
        model('recharge')->saveRecharge($data);
        $this->redirect('recharge');
    }


    public function productShow($i,$v){
        model('product')->changeShow($i,$v);
        $this->redirect('product');
    }

   public function rechargeShow($i,$v){
        model('recharge')->changeShow($i,$v);
        $this->redirect('recharge');
    }



    public function deleteProduct($id){
        model('product')->deleteProduct($id);
        $this->redirect('product');
    }

    public function deleteRecharge($id){
        model('recharge')->deleteRecharge($id);
        $this->redirect('recharge');
    }


    public function recharge(){
        $data = model('recharge')->getAllRecharge();
        $this->assign('data',$data);
        return view('recharge');
    }


    public function addRecharge(){

        return view('addRecharge');
    }

    public function updateRecharge($id){
        $product = model('recharge')->where('id',$id)->find();
        $this->assign('product',$product);
        return view('updateRecharge');
    }


}